package cc.chinagps.gateway.unit.eg.upload.cmds;

import cc.chinagps.gateway.client.TransferDeviceManager;
import cc.chinagps.gateway.log.LogManager;
import cc.chinagps.gateway.unit.UnitServer;
import cc.chinagps.gateway.unit.UnitSocketSession;
import cc.chinagps.gateway.unit.eg.pkg.EGPackage;
import cc.chinagps.gateway.unit.eg.upload.bean.EGRealTimeInfo;
import cc.chinagps.gateway.unit.eg.util.EGUploadUtil;
import org.apache.log4j.Logger;

public class Cmd02 extends CheckLoginHandler {
    private Logger logger_debug = Logger.getLogger(LogManager.LOGGER_NAME_DEBUG);

    @Override
    public boolean handlerPackageSessionChecked(EGPackage pkg, UnitServer server, UnitSocketSession session)
            throws Exception {
        byte data[] = pkg.getData();
        int pos = 0;
        String callLetter = session.getUnitInfo().getCallLetter();
        EGRealTimeInfo realTimeInfo = EGRealTimeInfo.parse(data, pos);
        realTimeInfo.setHistory(false);
        realTimeInfo.setSoftwareVersion(pkg.getHead().getSoftwareVersion());
        logger_debug.debug("[EG][Cmd02][" + callLetter + "]recv realTimeInfo:" + realTimeInfo);
        EGUploadUtil.handleRealTimeInfo(pkg, server, session, realTimeInfo);
        TransferDeviceManager.instance.clientSendRealtimeData(callLetter, realTimeInfo, pkg);
        return true;
    }
}